﻿// JScript 文件

function PagePannel()
{
    this.m_handle = document.getElementById("divPage");
    
    this.m_PageCount = 0;
    
    this.m_object = {};
    
    //显示页码
    this.PageChangeShow = function(object)
    {
        this.m_object = object;
        
        this.m_handle.innerHTML = '';
        
        this.LoadPageNum(object);
    }
    
    //加载页码
    this.LoadPageNum = function(object)
    {
        this.m_PageCount = Math.ceil(this.m_object.tol / this.m_object.nPageSize);
        
        this.m_handle.innerHTML = "<span>共" + this.m_object.tol + "条/" + this.m_PageCount + "页</span>";
                
        //显示 首页.  前10页
        
        this.m_handle.innerHTML += this.checkFrontTen(object);
        
        //定位显示的页码
        
        if(this.m_PageCount <= 10 || this.m_object.nCurPage <= 10)
        {
            for(var i = 1 ; i <= this.m_PageCount && i <= 10; i ++)
            {
                this.m_handle.innerHTML += this.AddPageItem(i);
            }
        }
        else
        { 
            //定位到显示的页码
            
            var PageNum = Math.floor((this.m_object.nCurPage - 1) / 10);
            {
                for(var i = (PageNum * 10 + 1) ; i <= this.m_PageCount && i <= (PageNum + 1) * 10 ; i ++)
                {
                    this.m_handle.innerHTML += this.AddPageItem(i);
                }
            }
        }
        
        //显示 后10页 . 末页
        
        this.m_handle.innerHTML +=  this.checkBackTen(object);
        
        //显示高亮
        
        this.PageLuminance(this.m_object.nCurPage);
    }
    
    //添加页码
    
    this.AddPageItem = function(strNum)
    {
        var strHtml = "<span id=\"Page_" + strNum + "\"><a href=\"javascript:void(0);\" onclick='PagePannel.OnClickPageItem(" + strNum + ");'>" + strNum + "</a></span>";
        
        return strHtml;
    }
    
    //显示前10页
    
    this.checkFrontTen = function(object)
    {
        var strHtml = "<span><a href=\"javascript:void(0);\" onclick='PagePannel.OnClickPageItem(1);'>首页</a></span>";
        
        if(this.m_object.nCurPage > 10)
        {
            strHtml += "<span><a href=\"javascript:void(0);\" onclick='PagePannel.OnClickPageItem(" + (this.m_object.nCurPage - 10) + ");'>前10页</a></span>";
        }
        else
        {
            strHtml += "<span>前10页</span>";
        }
        
        return strHtml;
    }
    
    //显示后10页
    
    this.checkBackTen = function(object)
    {
        var strHtml = "";
        
        if(this.m_PageCount > 10 && ((((Math.floor(this.m_object.nCurPage / 10) * 10) + 1) < this.m_PageCount &&  this.m_object.nCurPage % 10 != 0) || (this.m_object.nCurPage % 10 == 0 && this.m_object.nCurPage < this.m_PageCount) ))
        {
            strHtml += "<span><a href=\"javascript:void(0);\" onclick='PagePannel.OnClickPageItem(" + (this.m_object.nCurPage + 10) + ");'>后10页</a></span>";
        }
        else
        {
            strHtml += "<span>后10页</span>";
        }
        strHtml += "<span><a href=\"javascript:void(0);\" onclick='PagePannel.OnClickPageItem(" + this.m_PageCount + ");'>末页</a></span>";
        
        return strHtml;
    }
    
    //当前页高亮
    
    this.PageLuminance = function(PageIndex)
    {
        try
        {
            document.getElementById("Page_" + PageIndex).className = 'on';
        }
        catch(e)
        {
        }
    }
}

PagePannel.OnClickPageItem = function(nCurPage)
{
    try
    {
        CViewMgr.sm_viewMgr.m_viewPagePannel.m_object.nCurPage = nCurPage;
        
        CControl.sm_instance.OnMessage("OnClickPageItem", CControl.sm_ActionList.clickPageItem, CViewMgr.sm_viewMgr.m_viewPagePannel.m_object);
    }
    catch(e)
    {
        alert(e.Message);
    }
}